package cn.wfu.rlrjds.web.admin.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.wfu.rlrjds.app.repaire.service.IRepaireService;
import cn.wfu.rlrjds.web.admin.domain.Admin;

@Controller
@RequestMapping(value = "/web/admin")
public class AdminController {
	@Autowired
	private IRepaireService repaireService;

	@RequestMapping(value = "/login")
	public String login(HttpServletRequest request, Admin form) {
		Subject subject = SecurityUtils.getSubject();
		UsernamePasswordToken token = new UsernamePasswordToken(
				form.getUsername(), form.getPassword());
		try {
			subject.login(token);
			List<Integer> goods_type = this.repaireService.findTypeCount();
			List<Integer> apartmentGoodsCount = this.repaireService
					.findApartmentGoodsCount();
			List<Integer> apartmentNetCount = this.repaireService
					.findApartmentNetCount();
			List<Integer> schoolGoodsCount = this.repaireService
					.findSchoolGoodsCount();
			request.setAttribute("goods_type", goods_type);
			request.setAttribute("apartmentGoodsCount", apartmentGoodsCount);
			request.setAttribute("apartmentNetCount", apartmentNetCount);
			request.setAttribute("schoolGoodsCount", schoolGoodsCount);
			return "index";
		} catch (Exception e) {
			e.printStackTrace();
			request.setAttribute("user", form);
			request.setAttribute("msg", "用户名或密码错误！");
			return "login";
		}

	}
}
